import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import LayoutContent from '../views/Layout/LayoutContent.vue'

export const defaultRoutes: Array<RouteRecordRaw> = [
  {
    path: '',
    redirect: '/home',
    meta: {
      hidden: true
    }
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录',
      hidden: true
    },
    component: () => import('../views/Login/UserLogin.vue')
  },
  {
    path: '/home',
    name: 'home',
    meta: {
      title: '首页',
      icon: 'overview'
    },
    redirect: '/home/overview',
    component: LayoutContent,
    children: [
      {
        path: 'overview',
        name: 'home_overview',
        meta: {
          title: '看板'
        },
        component: () => import('../views/Home/OverView.vue')
      }
    ]
  }
]

export const errorRoutes: Array<RouteRecordRaw> = [
  {
    path: '/502',
    name: '502',
    meta: {
      title: '权限不足',
      hidden: true
    },
    component: () => import('../views/Error/502Page.vue')
  },
  {
    path: '/:catchAll(.*)',
    redirect: '502'
  }
]

export const routes: Array<RouteRecordRaw> = [
  {
    path: '/permission',
    name: 'permission',
    meta: {
      title: '权限管理',
      icon: 'permission'
    },
    redirect: '/permission/user',
    component: LayoutContent,
    children: [
      {
        path: 'user',
        name: 'permission_user',
        meta: {
          title: '用户管理'
        },
        component: () => import('../views/PermissionManagement/UserManagement.vue')
      },
      {
        path: 'role',
        name: 'permission_role',
        meta: {
          title: '角色管理'
        },
        component: () => import('../views/PermissionManagement/RoleManagement.vue')
      },
      {
        path: 'menu',
        name: 'permission_menu',
        meta: {
          title: '菜单管理'
        },
        component: () => import('../views/PermissionManagement/MenuManagement.vue')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes: defaultRoutes
})

export default router
